package com.supermap.business.common;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.agrinfo.AgrinfoService;
import com.supermap.dubbo.api.disaster.DisasterService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author xiaolu
 * @date 2018/8/6 下午4:36
 */
@Controller
@RequestMapping("search")
public class SearchController {

    @Reference
    private AgrinfoService agrinfoService;

    @Reference
    private DisasterService disasterService;

    @RequestMapping("searchAgriAndDisaster")
    @ResponseBody
    JSONUtil searchAgrInfoAndDisasterByShowName(@RequestParam("showName") String showName, @RequestParam("type") String type, @RequestParam("areaCode") String areaCode) {
        if (!showName.contains("%")) {
            showName = "%" + showName + "%";
        }
        if (!areaCode.contains("%")) {
            areaCode = areaCode + "%";
        }
        if (type.equals("zaiqing")) {
            return disasterService.searchDisasterByShowName(showName, areaCode);
        }
        else {
            return agrinfoService.searchAgrInfoByShowName(showName, areaCode);
        }
    }
}
